package com.yuyou.fn.tradingservice.service.impl;

import com.github.wens.mybatisplus.examples.Example;
import com.github.wens.mybatisplus.plugins.Page;
import com.yuyou.fn.common.util.BeanUtils;
import com.yuyou.fn.common.util.CriteriaUtils;
import com.yuyou.fn.common.util.TimeUtils;
import com.yuyou.fn.tradingservice.vo.ServiceMerchantVo;
import org.springframework.stereotype.Service;

import com.yuyou.fn.tradingservice.mapper.ServiceMerchantMapper;
import com.yuyou.fn.tradingservice.entity.ServiceMerchant;
import com.yuyou.fn.tradingservice.service.IServiceMerchantService;
import com.github.wens.framework.service.impl.SuperServiceImpl;

/**
 *
 * ServiceMerchant 表数据服务层接口实现类
 *
 */
@Service
public class ServiceMerchantServiceImpl extends SuperServiceImpl<ServiceMerchantMapper, ServiceMerchant,Long> implements IServiceMerchantService {


    @Override
    public Long saveOrUpdate(ServiceMerchantVo serviceMerchantVo) {
        ServiceMerchant serviceMerchant = new ServiceMerchant();
        BeanUtils.copyProperties(serviceMerchant,serviceMerchantVo);
        if (serviceMerchant.getMerchantId() == null){
            serviceMerchant.setCreateTime(TimeUtils.now());
            serviceMerchant.setUpdateTime(TimeUtils.now());
            insertSelective(serviceMerchant);
            return serviceMerchant.getMerchantId();
        }else {
            serviceMerchant.setUpdateTime(TimeUtils.now());
            updateSelectiveById(serviceMerchant);
            return serviceMerchant.getMerchantId();
        }
    }

    @Override
    public Page<ServiceMerchant> findMerchantPage(ServiceMerchantVo serviceMerchant, int pageNo, int pageSize) {
        Example<ServiceMerchant> example = ServiceMerchant.createExample();
        Example.Criteria criteria = example.createCriteria();
        CriteriaUtils.fillCondition(criteria,serviceMerchant);
        return findPageByExample(example,pageNo,pageSize);
    }
}